using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Users;

namespace ThridGroup.ERP.Web.Pages;

public class IndexModel : ERPPageModel
{
    private readonly ICurrentUser _currentUser;
    
    public DashboardData Dashboard { get; set; }
    
    public IndexModel(ICurrentUser currentUser)
    {
        _currentUser = currentUser;
    }
    
    public async Task OnGetAsync()
    {
        // 初始化仪表板数据
        Dashboard = new DashboardData
        {
            OrderCount = 345,
            OrderGrowthRate = 5.2m,
            
            Sales = 128450m,
            SalesGrowthRate = -2.3m,
            
            PendingTickets = 15,
            EarliestDeadline = new DateTime(2023, 6, 30),
            
            InventoryTurnover = 89,
            InventoryTurnoverGrowthRate = 1.5m,
            
            TodoItems = GetTodoItems()
        };
        
        await Task.CompletedTask;
    }
    
    private List<TodoItem> GetTodoItems()
    {
        return new List<TodoItem>
        {
            new TodoItem
            {
                Id = 1,
                Title = "完成月度销售报表",
                DueDate = new DateTime(2023, 6, 30),
                Priority = TodoPriority.High,
                IsCompleted = false
            },
            new TodoItem
            {
                Id = 2,
                Title = "处理客户投诉单",
                DueDate = new DateTime(2023, 6, 25),
                Priority = TodoPriority.Urgent,
                IsCompleted = false,
                IsOverdue = true
            },
            new TodoItem
            {
                Id = 3,
                Title = "审核新员工申请",
                DueDate = new DateTime(2023, 6, 27),
                Priority = TodoPriority.Medium,
                IsCompleted = true,
                CompletedDate = new DateTime(2023, 6, 27)
            },
            new TodoItem
            {
                Id = 4,
                Title = "准备季度业绩会议",
                DueDate = new DateTime(2023, 7, 5),
                Priority = TodoPriority.Normal,
                IsCompleted = false
            }
        };
    }
}

public class DashboardData
{
    public int OrderCount { get; set; }
    public decimal OrderGrowthRate { get; set; }
    
    public decimal Sales { get; set; }
    public decimal SalesGrowthRate { get; set; }
    
    public int PendingTickets { get; set; }
    public DateTime EarliestDeadline { get; set; }
    
    public int InventoryTurnover { get; set; }
    public decimal InventoryTurnoverGrowthRate { get; set; }
    
    public List<TodoItem> TodoItems { get; set; }
}

public class TodoItem
{
    public int Id { get; set; }
    public string Title { get; set; }
    public DateTime DueDate { get; set; }
    public DateTime? CompletedDate { get; set; }
    public TodoPriority Priority { get; set; }
    public bool IsCompleted { get; set; }
    public bool IsOverdue { get; set; }
}

public enum TodoPriority
{
    Low,
    Normal,
    Medium,
    High,
    Urgent
}
